﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using RTW.OA.Models;
using RTW.OA.Controllers;
using RTW.OA.Areas.Overseas.Servers;
using RTW.OA.Attributes;

namespace RTW.OA.Areas.Overseas.Controllers
{
    [CheckLogin(IsChildPage = true)]
    public class CaseController : BaseController
    {
        private CaseServers caseServers;

        public CaseController()
        {
            caseServers = new CaseServers();
        }
        //涉外案件
        // GET: Overseas/Case
        public ActionResult Index()
        {
            return View();
        }

        public string GetDataTableJsonResult()
        {
            var datalist = caseServers.GetOverseasCaseList();
            
            return JsonConvert.SerializeObject(datalist);
        }

        public JsonResult FileArchive(int id)
        {
            caseServers.UpdateArchiveStatus(id);
            /* 调用归档数据接口
            document_archive_wenshu model
            var postData = new
            {
                type = "InsertWenShu", //执行方法
                model.ND, //年度
                model.JG, //机构
                model.ZRZ, //责任者
                model.WH, //文号
                model.AJTM, //案卷题名
                model.RQ, //日期
                model.YS, //页数
                model.MJ, //密级
                model.GDR, //归档人
                model.WJ
            };
            string strUrl = "http://10.42.0.68:8088/api/FileArchive.ashx";
            byte[] data = Encoding.UTF8.GetBytes(postData.ToString());

            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strUrl);
            myRequest.Method = "POST";
            myRequest.ContentType = "application/x-www-form-urlencoded";
            myRequest.ContentLength = data.Length;
            Stream newStream = myRequest.GetRequestStream();

            // 发送数据 
            newStream.Write(data, 0, data.Length);
            newStream.Close();

            //得到服务器端的返回
            HttpWebResponse res = myRequest.GetResponse() as HttpWebResponse;
            StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.GetEncoding("utf-8"));
            Response.Write(sr.ReadToEnd()); //或者MessageBox.Show(sr.ReadToEnd());
            sr.Close();
            res.Close();
            */

            return Json(new
            {
                code = 100,
                msg = "提交成功"
            }, JsonRequestBehavior.AllowGet);
        }

        public ActionResult Details(int id)
        {
            overseas_case model = new overseas_case();
            model = caseServers.GetModelById(id.ToString());
            return View(model);
        }
    }
}